<?xml version="1.0" encoding="UTF-8"?>
<!-- 
	Copyright (c) 2012 Mia-Software. All rights reserved. This program and 
	the accompanying materials are made available under the terms of the Eclipse 
	Public License v1.0 which accompanies this distribution, and is available 
	at http://www.eclipse.org/legal/epl-v10.html 
	
	Contributors: 
		Herve ESTEGUET (Mia-Software) - Bug 381352 - [Releng] There must be a project to configure the build by tycho
-->
<xsl:stylesheet version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common"
	extension-element-prefixes="exsl" xmlns:m2="http://maven.apache.org/POM/4.0.0">
	<xsl:output indent="yes" />

	<xsl:param name="testDependencies" />
	<xsl:param name="skipTests" />
	<xsl:param name="tychoVersion" />
	<xsl:param name="testsWorkspaceRoot"/>
	<xsl:param name="testsReportsRoot"/>
	<xsl:param name="testsHtmlReportDir"/>

	<xsl:template match="/">
		<project
			xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
			xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
			<xsl:apply-templates select="//m2:project/*[name()!='build']" />
			<build>
				<plugins>
					<plugin>
						<groupId>org.eclipse.tycho</groupId>
						<artifactId>tycho-surefire-plugin</artifactId>
						<version><xsl:value-of select="$tychoVersion"/></version>
						<configuration>
							<skipTests><xsl:value-of select="$skipTests" /></skipTests>
							<testFailureIgnore>true</testFailureIgnore>
							<failIfNoTests>false</failIfNoTests>
							<forkedProcessTimeoutInSeconds>5000</forkedProcessTimeoutInSeconds>
							<argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
							<application>org.eclipse.ui.ide.workbench</application>
							<reportsDirectory><xsl:value-of select="$testsReportsRoot" /></reportsDirectory>
							<work><xsl:value-of select="concat($testsWorkspaceRoot,'/','${project.artifactId}')"/></work>
							<xsl:copy-of select="document($testDependencies)/*" />
						</configuration>
						<executions>
							<execution>
								<id>default-test</id>
								<configuration>
									<includes>
										<include>**/AllTestsNotInUIThread.class</include>
									</includes>
									<useUIThread>false</useUIThread>
									<useUIHarness>true</useUIHarness>
								</configuration>
								<goals>
									<goal>test</goal>
								</goals>
								<phase>test</phase>
							</execution>
							<execution>
								<id>AllUITests</id>
								<configuration>
									<includes>
										<include>**/AllTestsInUIThread.class</include>
									</includes>
									<useUIThread>true</useUIThread>
									<useUIHarness>true</useUIHarness>
								</configuration>
								<goals>
									<goal>test</goal>
								</goals>
								<phase>test</phase>
							</execution>
						</executions>
					</plugin>
					<!-- In case there were others plugins configurations -->
					<xsl:apply-templates select="//m2:project/m2:build/m2:plugins/*" />
				</plugins>
				<!-- In case of other build configurations -->
				<xsl:apply-templates select="//m2:project/m2:build/*[name()!='plugins']" />
			</build>
		</project>
	</xsl:template>

	<xsl:template match="m2:*[name()!='build']|@*">
		<xsl:copy-of select="." />
	</xsl:template>

</xsl:stylesheet>
